package com.samphanie.auiu.common.http

import android.accounts.AccountManager
import android.text.TextUtils
import com.samphanie.auiu.common.utils.LocalCache
import com.samphanie.auiu.common.utils.SPUtil
import com.samphanie.auiu.library.log.AuiuLog
import com.samphanie.auiu.library.restful.AuiuInterceptor

/**
 * @author Dries
 **/
class BizInterceptor: AuiuInterceptor {
    override fun intercept(chain: AuiuInterceptor.Chain): Boolean {
        if (chain.isRequestPeriod) {
            val request = chain.request()

            // val token = AccountManager.getAuthorization()

            val token = LocalCache.getInstance().getString(JWT_TOKEN_PREFIX) + LocalCache.getInstance().getString(JWT_TOKEN)
            request.addHeader("Authorization", token )
        } else if (chain.response() != null) {
            AuiuLog.dt("BizInterceptor", chain.request().endPointUrl())
            AuiuLog.dt("BizInterceptor", chain.response()!!.rawData)
        }

        return false
    }

    companion object {
        private const val JWT_TOKEN = "JWT_TOKEN"
        private const val JWT_TOKEN_PREFIX = "JWT_TOKEN_PREFIX"
    }
}